package com.ydsungan.service.impl;

import com.ydsungan.dao.CategoryMapper;
import com.ydsungan.dao.FileMapper;
import com.ydsungan.dao.ShareMapper;
import com.ydsungan.pojo.*;
import com.ydsungan.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileMapper fileMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private ShareMapper shareMapper;

    @Override
    public List<File> listFile(FileExample fileExample) {
        return fileMapper.selectByExample(fileExample);
    }

    @Override
    public List<Category> listCategory(CategoryExample categoryExample) {
        return categoryMapper.selectByExample(categoryExample);
    }

    @Override
    public int updateFileByExample(File file) {
        return fileMapper.updateByPrimaryKeySelective(file);
    }

    @Override
    public File selectFileById(Integer id) {
        return fileMapper.selectByPrimaryKey(id);
    }

    @Override
    public long countFiles() {
        FileExample fileExample = new FileExample();
        return fileMapper.countByExample(fileExample);
    }

    @Override
    public long countNeedCheckFiles() {
        ShareExample shareExample = new ShareExample();
        ShareExample.Criteria criteria = shareExample.createCriteria();
        criteria.andStatusEqualTo(-1);
        return shareMapper.countByExample(shareExample);
    }
}
